package com.hua.syn;

import java.util.concurrent.CopyOnWriteArrayList; //这个Java的并发编程包

//测试JUC安全类型的集合 ,这个类本来就是安全的
public class TestJUC {
    public static void main(String[] args) {

        CopyOnWriteArrayList<String > copyOnWriteArrayList = new CopyOnWriteArrayList<String >();
        for (int i = 0; i < 1000; i++) {
            new Thread(()->{
                copyOnWriteArrayList.add(Thread.currentThread().getName());
            }).start();
        }
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(copyOnWriteArrayList.size());
    }
}
